const searchFormList = [
  { label: '关键词', value: 'query', type: 'input', width: '200px' },
  { label: '', width: '200px', value: 'btn', type: 'slot' }
];

const tables = [ // 表格数据
  { label: '记录ID', value: 'id', width: 80 },
  { label: '唯一标识ID', value: 'packetid', width: 120 },
  { label: '应用名称', value: 'name', width: 120 },
  { label: '应用ID', value: 'appid', width: 160 },
  { label: '登录校验码', value: 'secret', width: 240 },
  { label: '商户号ID', value: 'mchnid', width: 100 },
  { label: '支付校验码', value: 'paykey', width: 240 },
  { label: 'SSL公钥Pem', value: 'sslpem'},
  { label: 'SSL公钥Key', value: 'sslkey'},
  { label: '更新时间', value: 'stime', type: 'slot', width: 120 },
  { label: '操作', type: 'slot', value: 'btn', width: 160 }
];

const fieldList = [ // 新增弹出数据
  { label: '唯一标识ID', value: 'packetid', type: 'input', width: '360px' },
  { label: '应用名称', value: 'name', type: 'input', width: '360px' },
  { label: '应用ID', value: 'appid', type: 'input', width: '360px' },
  { label: '登录校验码', value: 'secret', type: 'input', width: '360px' },
  { label: '商家ID', value: 'mchnid', type: 'input', width: '360px' },
  { label: '支付校验码', value: 'paykey', type: 'input', width: '360px' },
  { label: 'SSL公钥Pem', value: 'sslpem', type: 'textarea', width: '460px' },
  { label: 'SSL公钥Key', value: 'sslkey', type: 'textarea', width: '460px' },
];

const rules = {
  packetid: [{ required: true, message: '请输入唯一标识ID', trigger: 'change' }],
  name: [{ required: true, message: '请输入应用名称', trigger: 'change' }],
  appid: [{ required: true, message: '请输入应用ID', trigger: 'change' }],
  secret: [{ required: true, message: '请输登录校验码', trigger: 'change' }],
  mchnid: [{ required: true, message: '请输商家ID', trigger: 'change' }],
  sslpem: [{ required: true, message: '请输入SSL公钥Pem', trigger: 'change' }],
  sslkey: [{ required: true, message: 'SSL公钥Key', trigger: 'change' }],
  paykey: [{ required: true, message: '请输入支付校验码', trigger: 'change' }]
};

const fieldData = (data) => {
  var dataset = {};
  for (var idx = 0; idx < fieldList.length; idx++) {
    var ckey = fieldList[idx].value;
    dataset[ckey] = (data) ? data[ckey] : '';
  }
  dataset.id = (data && data.id) ? data.id : 0;
  return dataset;
}

export default {
  searchFormList, tables, fieldList, fieldData, rules
};
